#ifndef __LENGTH_H__
#define __LENGTH_H__

#include <iostream>
#include <Unit.h>
#include <UnitFormat.h>

class Unit;
class UnitFormat;

typedef int UnitAmount;

template <class T>
class Measure
{
  public :
    Measure(const UnitAmount& value, const T& unit) :value_m(value), unit_m(unit) {}

    bool operator==(const Measure& meas) const 
    { 
       return unit_m.convert2MinUnit(value_m) == meas.unit_m.convert2MinUnit(meas.value_m); 
    }

    bool operator!=(const Measure& meas) const 
    { 
       return !(*this==meas); 
    }

    Measure operator+(const Measure& meas) const
    {
      UnitAmount value = unit_m.convert2MinUnit(value_m) + meas.unit_m.convert2MinUnit(meas.value_m);
      return Measure(value, T::minUnit());
    }

    void output(std::ostream& out, const UnitFormat& unitFormat) const
    {
       unitFormat.unitOutput(out,value_m,unit_m);
    }

private:
    UnitAmount value_m;
    const T&   unit_m; 
};

#endif

